import { Controller, Get } from '@nestjs/common';
import { roleService } from './role.service';
import { UserService } from 'src/user/user.service';
import { Res } from 'src/utils/Res';

@Controller()
export class RoleController {
  constructor(
    private readonly roleService: roleService,
    private readonly UserService: UserService,
  ) {}
  @Get('/role')
  Hello() {
    return new Promise((resolve, reject) => {
      this.UserService.findAll().then(async (res) => {
        const result = await this.roleService.findAll();
        if (!res) {
          resolve(Res([]))
        } else {
          /**
           * 匹配角色
           */
          const results = res.map((item) => {
            const element = result.find((itemm) => itemm.id === item.role);
            return { ...item, role: element ? element.role : null };
          });
          resolve(Res(results));
        }
      });
    });
  }
}
